<template>
  <div class="hello">
    <h1>{{ msg }}</h1>
    <h4>页面直接获取：{{ this.$store.state.count }}</h4>
    <h4>getters计算后获取：{{ this.$store.getters.getStateCount }}</h4>
    <hr>
    <h4>count的值：{{ this.$store.state.count }}</h4>
    <p>
      <button @click="add">+</button>
      <button @click="reduce">-</button>
    </p>
  </div>
</template>

<script>
export default {
  name: 'HelloWorld',
  props: {
    msg: String
  },
  methods: {
    add(){
      // this.$store.commit('add') // 这是通过 mutations 直接修改 state 里面的 count 值
      this.$store.dispatch('add') // 这是通过 actions 提交 mutations 再去修改值
    },
    reduce(){
      var n = 10
      // this.$store.commit('reduce')
      this.$store.dispatch('reduce', n)
    }
  },
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
h3 {
  margin: 40px 0 0;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>
